package com.changgou.pay.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class RabbitConfig {

    @Autowired
    private Environment env;

    //定义队列
    @Bean("orderQueue")
    public Queue orderQueue(){
        //return QueueBuilder.durable(env.getProperty("mq.pay.queue.order")).withArgument("x-queue-type", "classic").build();
        return QueueBuilder.durable(env.getProperty("mq.pay.queue.order")).build();
    }

    //定义交换机
    @Bean("orderExchange")
    public Exchange orderExchange(){
        return ExchangeBuilder.directExchange(env.getProperty("mq.pay.exchange.order")).build();
    }

    //绑定队列与交换机
    @Bean("orderBinding")
    public Binding orderBinding(@Qualifier("orderQueue")Queue queue, @Qualifier("orderExchange")Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(env.getProperty("mq.pay.routing.key")).noargs();
    }
}
